﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Xml;
using System.Data;
using MES.DataGateway.DBUtility;
using System.Collections;
using Newtonsoft.Json;

namespace MESWebService
{
    /// <summary>
    /// QMSTOMESservice 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    public class QMSTOMESservice : System.Web.Services.WebService
    {
        private QmsToMesDataMethod qmsTOmes = new QmsToMesDataMethod();

        #region  给QMS的统一接口入口方法，适用于访问量不大的接口,根据字段方法传参判断调用不同方法
        /// <summary>
        /// QMS质量调用MES统一接口入口方法
        /// </summary>
        /// <param name="strMessage"></param>
        /// <returns></returns>
        [WebMethod]
        public string QMS_Send_WebService(string strMessage)
        {
            LogHelp.SetConfig();
            XmlDocument myxml = new XmlDocument();
            myxml.LoadXml(strMessage);
            //获取内容
            myxml.LoadXml(myxml.SelectSingleNode("ReqMsg/document").InnerText);
            string mesFun = myxml.SelectSingleNode("root/mesFunName").InnerText;
            LogHelp.WriteLog("QMS_Send_WebService" + "_" + mesFun + "接收到的xml是:" + strMessage);//接收日志
            try
            {
                XmlNode mesDoc = myxml.SelectSingleNode("root/mesDocument");
                string strMsg = "";//返回参数
                switch (mesFun)
                {
                    case "sendArmyCheckList"://军检项目推送接口 add by longb 2022-12-27
                        strMsg = sendArmyCheckList(mesDoc);
                        break;
                    case "receiveIqsResult"://理化试验结果集成接口(返回) add by longb 2023-03-06
                        strMsg = receiveIqsResult(mesDoc);
                        break;
                    case "QMSArmyInstoreResult"://产品军检结果接口
                        strMsg = QMSArmyInstoreResult(mesDoc);
                        break;
                    case "QMS_Send_SpecMilitaryCheckInfoResult_Service"://工序军检结果接口 add by zhangrj 2022-12-26
                        strMsg = QMS_Send_SpecMilitaryCheckInfoResult_Service(mesDoc);
                        break;
                    case "DealFaultBillResult"://2.5排故单审理结果接口 add by longb 2023-04-13
                        strMsg = DealFaultBillResult(mesDoc);
                        break;
                    case "dealFaultBillResolveResult"://2.7排故单处理结果审理接口 add by longb 2023-04-13
                        strMsg = DealFaultBillResolveResult(mesDoc);
                        break;
                    case "ZSGJCheckSubmitBillResult"://2.9故检提交单审理结果接口 add by longb 2023-04-13
                        strMsg = ZSGJCheckSubmitBillResult(mesDoc);
                        break;
                    case "exchangeBillResult"://2.11周转/串件审理结果接口 add by longb 2023-04-13
                        strMsg = ExchangeBillResult(mesDoc);
                        break;
                    #region MyRegion
                    case "qaProblemHearResultNotify"://系统质量问题审理结果接口 modify by longb 2023-04-12
                        strMsg = qaProblemHearResultNotify(mesDoc);
                        break;
                    case "firstThingAuth"://首件鉴定目录接口 modify by longb 2023-04-12
                        strMsg = firstThingAuth(mesDoc);
                        break;
                    case "firstThingAuthDirControlPointRelease"://首件鉴定控制点解除接口 modify by longb 2023-04-12
                        strMsg = firstThingAuthDirControlPointRelease(mesDoc);
                        break;
                    case "pushQaProductReviewDir"://质量评审目录接口 modify by longb 2023-04-12
                        strMsg = pushQaProductReviewDir(mesDoc);
                        break;
                    case "qaProductReviewDirControlPointRelease"://产品质量评审控制点解除接口 modify by longb 2023-04-12
                        strMsg = qaProductReviewDirControlPointRelease(mesDoc);
                        break;
                    case "pushCraftReviewDir"://工艺评审控制点接口 modify by longb 2023-04-12
                        strMsg = pushCraftReviewDir(mesDoc);
                        break;
                    case "craftReviewDirControlPointRelease"://工艺评审控制点解除接口 modify by longb 2023-04-12
                        strMsg = craftReviewDirControlPointRelease(mesDoc);
                        break;
                    #endregion
                    default:
                        strMsg = RespMsg("false", "接收数据失败", "E", "系统服务找不到对应的【" + mesFun + "】方法");
                        break;
                }
                LogHelp.WriteOrcale("QMS_Send_WebService" + "_" + mesFun + "@^" + strMsg + "@^" + (strMessage.Replace("\'", "\"").Length > 4000 ? "xml太长" : strMessage.Replace("\'", "\"")) + "@^" + Convert.ToString(Guid.NewGuid()));//add:Wangjh 2017-8-30
                LogHelp.WriteLog("QMS_Send_WebService" + "_" + mesFun + "处理结果：" + strMsg);//处理结果日志
                return strMsg;
            }
            catch (Exception ex)
            {
                LogHelp.WriteOrcaleError("QMS_Send_WebService" + "_" + mesFun + "@^" + ex.Message.Replace("\'", "\"") + "@^" + (strMessage.Replace("\'", "\"").Length > 4000 ? "xml太长" : strMessage.Replace("\'", "\"")) + "@^" + Convert.ToString(Guid.NewGuid()), ex);//add:Wangjh 2017-8-30
                LogHelp.WriteError(ex.Message + strMessage, ex);
                return @"<?xml version='1.0' encoding='utf-8'?><ReqMsg><header><SysName>APP_MES</SysName><isSuccess>false</isSuccess></header><document><![CDATA[<TETTYP><RTYPE>E</RTYPE><RTMSG>" + ex.Message + "</RTMSG></TETTYP>]]></document></ReqMsg>";

            }
        }
        
        /// <summary>
        /// 军检项目推送接口 add by longb 2022-12-27
        /// </summary>
        /// <param name="mesDoc"></param>
        /// <returns></returns>
        public string sendArmyCheckList(XmlNode mesDoc)
        {
            var arrList = new ArrayList();
            var InsertSQL = @"INSERT INTO ArmyCheckDirInfo(ArmyCheckDirInfoID,ArmyYear,productModel,checkCustomer,armyCheckType,branchFactory,partDesc,partName,ProcessNo,specNo,specName,SpecDesc,Notes,isuse,CreateDate)
                                VALUES(lower(sys_guid()),'{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}',sysdate)";
            var JsonDic = JsonConvert.DeserializeObject<Dictionary<string, object>>(mesDoc.InnerText);
            var year = JsonDic["year"].ToString();//年度
            var productModel = JsonDic["productModel"].ToString();//产品型号
            var checkCustomer = JsonDic["checkCustomer"].ToString();//验收客户
            var armyCheckType = JsonDic["armyCheckType"].ToString();//军检类型
            var branchFactory = JsonDic["branchFactory"].ToString();//分厂
            var status = JsonDic["status"];//状态
            var armyCheckListSubList = JsonConvert.DeserializeObject<DataTable>(JsonDic["armyCheckListSubList"].ToString());//军检零组件详情 
            foreach (DataRow row in armyCheckListSubList.Rows)
            {
                var partName = row["partName"].ToString();//零组件名称
                var partCode = row["partCode"].ToString();//零组件号
                var processes = row["processes"].ToString();//工序号
                var armyCheckContent = row["armyCheckContent"].ToString();//军检内容
                var craftRulesNo = row["craftRulesNo"].ToString();//工艺规程号
                var remark = row["remark"].ToString();//备注
                var selectSQL = @"SELECT ArmyCheckDirInfoID FROM  ArmyCheckDirInfo WHERE  ARMYCHECKTYPE='{0}' AND ARMYYEAR='{1}' AND BRANCHFACTORY='{2}' AND PARTNAME='{3}' AND PROCESSNO='{4}'AND SPECNO='{5}'";
                DataTable dt = OracleHelper.Query(string.Format(selectSQL, armyCheckType, year, branchFactory, partCode, craftRulesNo, processes)).Tables[0];
                if (dt.Rows.Count > 0)
                {
                    var updateSQL = @"UPDATE ArmyCheckDirInfo SET NOTES='{0}',SPECDESC='{1}',ISUSE='{2}' WHERE ArmyCheckDirInfoID='{3}'";
                    arrList.Add(string.Format(updateSQL, remark, armyCheckContent, status, dt.Rows[0]["ArmyCheckDirInfoID"].ToString()));
                }
                else
                {
                    arrList.Add(string.Format(InsertSQL, year, productModel, checkCustomer, armyCheckType, branchFactory, partName, partCode, craftRulesNo, processes, "", armyCheckContent, remark, status));
                }
            }
            var msg = string.Empty;
            var result = OracleHelper.ExecuteSqlTran(arrList, ref msg);
            var resultDic = string.Empty;
            if (result)
            {
                resultDic = "<TETTYP><RTYPE>S</RTYPE><RTMSG>军检目录信息接收成功</RTMSG></TETTYP>";
            }
            else
            {
                resultDic = "<TETTYP><RTYPE>E</RTYPE><RTMSG>军检目录信息接收失败：" + msg + "</RTMSG></TETTYP>";
            }
            return @"<?xml version='1.0' encoding='utf-8'?><ReqMsg><header><SysName>APP_MES</SysName><isSuccess>true</isSuccess><message>true</message></header><document><![CDATA[" + resultDic + "]]></document></ReqMsg>";
        }

        /// <summary>
        /// 理化试验结果集成接口(返回) add by longb 2023-03-06
        /// </summary>
        /// <param name="mesDoc"></param>
        /// <returns></returns>
        public string receiveIqsResult(XmlNode mesDoc)
        {
            var arrList = new ArrayList();
            var updateSQL = @"update EntrustMeasurement set Status='{0}',IqsOrderQMSNoLH='{1}', FinishReportTime=to_date('{2}','yyyy-MM-dd hh24:mi:ss'),
                              TestResult='{3}',SendEmployeeName='{4}',SendDate=to_date('{5}','yyyy-MM-dd hh24:mi:ss'),RecvEmployeeName='{6}',
                              RecvDate=to_date('{7}','yyyy-MM-dd hh24:mi:ss'),TreatNote='{8}' where QMSENTRUSTNAME='{9}'";
            var EntrustName = mesDoc.SelectSingleNode("entrustName").InnerText;//请托单号
            var Status = mesDoc.SelectSingleNode("status").InnerText;//状态
            var IqsOrderQMSNoLH = mesDoc.SelectSingleNode("iqsOrderQMSNoLH").InnerText;//试验报告单号
            var FinishReportTime = mesDoc.SelectSingleNode("finishReportTime").InnerText;//报告完成日期
            var TestResult = mesDoc.SelectSingleNode("testResult").InnerText;//试验结果
            var SendEmployeeName = mesDoc.SelectSingleNode("sendEmployeeName").InnerText;//送料人
            var SendDate = mesDoc.SelectSingleNode("sendDate").InnerText;//送样时间
            var RecvEmployeeName = mesDoc.SelectSingleNode("recvEmployeeName").InnerText;//取样人
            var RecvDate = mesDoc.SelectSingleNode("recvDate").InnerText;//取样时间
            var Note = mesDoc.SelectSingleNode("note").InnerText;//备注

            arrList.Add(string.Format(updateSQL, Status, IqsOrderQMSNoLH,FinishReportTime,TestResult,SendEmployeeName,SendDate,RecvEmployeeName,RecvDate,Note, EntrustName));
            var msg = string.Empty;
            var result = OracleHelper.ExecuteSqlTran(arrList, ref msg);
            var resultDic = string.Empty;
            if (result)
            {
                return RespMsg("true", "接收数据成功", "S", "理化试验结果接收成功");
            }
            else
            {
                return RespMsg("true", "接收数据成功", "E", "理化试验结果接收失败：" + msg);
            }
        }

        /// <summary>
        /// QMS工序军检返回接口 add by zhangrj 2022-12-26
        /// </summary>
        /// <param name="mesDoc"></param>
        /// <returns></returns>
        public string QMS_Send_SpecMilitaryCheckInfoResult_Service(XmlNode mesDoc)
        {
            string mfgOrderName = mesDoc.SelectSingleNode("MfgOrderName").InnerText;//订单号
            string containerName = mesDoc.SelectSingleNode("ContainerName").InnerText;//批次号
            string productName = mesDoc.SelectSingleNode("ProductName").InnerText;//件号
            string specNo = mesDoc.SelectSingleNode("SpecNO").InnerText;//工序号
            //查询mes是否有军检提交,未反馈的数据
            string strSql = "select * from ArmyCheckSendToQMS ac WHERE ac.containername = '{0}' AND ac.mfgordername = '{1}' AND ac.specno = '{2}'";
            DataTable dt = OracleHelper.Query(string.Format(strSql, containerName, mfgOrderName, specNo)).Tables[0];
            if (dt.Rows.Count == 0)
            {
                return @"<?xml version='1.0' encoding='utf-8'?><ReqMsg><header><SysName>APP_MES</SysName><isSuccess>false</isSuccess></header><document>" + "未找到工序军检提交记录" + "</document></ReqMsg>";
            }
            string acceptanceQty = mesDoc.SelectSingleNode("AcceptanceQty").InnerText;//确认合格数
            string reworkQty = mesDoc.SelectSingleNode("ReworkQty").InnerText;//返修数
            string lossQty = mesDoc.SelectSingleNode("LossQty").InnerText;//报废数
            string customerName = mesDoc.SelectSingleNode("CustomerName").InnerText;//顾客代表
            string customerDealDate = mesDoc.SelectSingleNode("CustomerDealDate").InnerText;//顾客代表审核时间

            //更新数据
            int i = OracleHelper.ExecuteSql(string.Format(@"UPDATE ArmyCheckSendToQMS ac SET ac.qms_customername = '{0}',ac.qms_dealdate = to_date('{1}','yyyy-MM-dd HH24:mi:ss')
,ac.qms_lossqty = '{2}',ac.qms_pssqty = '{3}',ac.qms_reworkqty = '{4}' WHERE ac.armychecksendtoqmsid = '{5}'",
customerName, customerDealDate, lossQty, acceptanceQty, reworkQty, dt.Rows[0]["Armychecksendtoqmsid"].ToString()));
            if (i > 0)
            {
                return @"<?xml version='1.0' encoding='utf-8'?><ReqMsg><header><SysName>APP_MES</SysName><isSuccess>true</isSuccess></header><document>" + "处理成功" + "</document></ReqMsg>";
            }
            else
            {
                return @"<?xml version='1.0' encoding='utf-8'?><ReqMsg><header><SysName>APP_MES</SysName><isSuccess>false</isSuccess></header><document>" + "数据库处理失败" + "</document></ReqMsg>";
            }
        }
        #endregion

        /// <summary>
        /// QMS产品军检结果接口
        /// add:Wangjh 20221221
        /// </summary>
        /// <param name="mesDoc"></param>
        /// <returns></returns>
        public string QMSArmyInstoreResult(XmlNode mesDoc)
        {
            string productName = mesDoc.SelectSingleNode("ProductName").InnerText;
            string realContainerNo = mesDoc.SelectSingleNode("ProductBatchNo").InnerText;
            //查询mes是否有军检提交,未反馈的数据
            string strSql = "select * from containerinstore ci where ci.charg='{0}' and ci.isuse=0 and ci.QMS_CusAuditDate is null";
            DataTable dt = OracleHelper.Query(string.Format(strSql, productName + "/" + realContainerNo)).Tables[0];
            if (dt.Rows.Count == 0)
            {
                return @"<?xml version='1.0' encoding='utf-8'?><ReqMsg><header><SysName>APP_MES</SysName><isSuccess>false</isSuccess></header><document>" + "未找到产品军检入库记录" + "</document></ReqMsg>";
            }

            Dictionary<string, string> para = new Dictionary<string, string>();
            //取值
            para.Add("QMS_Passqty", mesDoc.SelectSingleNode("AcceptanceQty").InnerText);
            para.Add("QMS_RepairQty", mesDoc.SelectSingleNode("ReworkQty").InnerText);
            para.Add("QMS_LossQty", mesDoc.SelectSingleNode("LossQty").InnerText);
            para.Add("QMS_Customer", mesDoc.SelectSingleNode("CustomerName").InnerText);
            para.Add("QMS_CusAuditDate", mesDoc.SelectSingleNode("CustomerDealDate").InnerText);

            //更新数据
            var i = OracleHelper.ExecuteSql(string.Format(@"update containerinstore ci set ci.qms_passqty={0},ci.qms_repairqty='{1}',ci.qms_lossqty='{2}',ci.qms_customer='{3}',
ci.qms_cusauditdate=to_date('{4}','yyyy/mm/dd hh24:mi:ss') where ci.containerinstoreid='{5}' ", para["QMS_Passqty"], para["QMS_RepairQty"], para["QMS_LossQty"],
                                                                                                 para["QMS_Customer"], para["QMS_CusAuditDate"], dt.Rows[0]["containerinstoreid"].ToString()));
            if (i > 0)
            {
                return @"<?xml version='1.0' encoding='utf-8'?><ReqMsg><header><SysName>APP_MES</SysName><isSuccess>true</isSuccess></header><document>" + "处理成功" + "</document></ReqMsg>";

            }
            else
            {
                return @"<?xml version='1.0' encoding='utf-8'?><ReqMsg><header><SysName>APP_MES</SysName><isSuccess>false</isSuccess></header><document>" + "数据库处理失败" + "</document></ReqMsg>";

            }
        }

        /// <summary>
        /// 排故单审理结果接口 
        /// add by longb 2023-04-13
        /// </summary>
        /// <param name="mesDoc"></param>
        /// <returns></returns>
        public string DealFaultBillResult(XmlNode mesDoc) 
        {
            string MfgOrderName = mesDoc.SelectSingleNode("MfgOrderName").InnerText;//订单号
            string EngineNO = mesDoc.SelectSingleNode("EngineNO").InnerText;//发动机号
            string DealFaultBillName = mesDoc.SelectSingleNode("DealFaultBillName").InnerText;//排故单号
            string CustomerName = mesDoc.SelectSingleNode("CustomerName").InnerText;//客户名称
            string CustomerDealDate = mesDoc.SelectSingleNode("CustomerDealDate").InnerText;//客户确认时间

            var updateSQL = @"update DealFaultBill set AuditDate=to_date('{0}','yyyy-MM-dd hh24:mi:ss'),
                                AuditEmployeeID=(select EmployeeID from Employee where FullName='{1}') where DealFaultBillName='{2}'";
            updateSQL = string.Format(updateSQL, CustomerDealDate, CustomerName, DealFaultBillName);
            if (OracleHelper.ExecuteSql(updateSQL) > 0)
            {
                return RespMsg("true", "接收数据成功", "S", "排故单审理结果接收成功");
            }
            else
            {
                return RespMsg("true", "接收数据成功", "E", "排故单审理结果接收失败");
            }
        }

        /// <summary>
        /// 排故单处理结果审理接口 
        /// add by longb 2023-04-13
        /// </summary>
        /// <param name="mesDoc"></param>
        /// <returns></returns>
        public string DealFaultBillResolveResult(XmlNode mesDoc) 
        {
            string MfgOrderName = mesDoc.SelectSingleNode("MfgOrderName").InnerText;//订单号
            string EngineNO = mesDoc.SelectSingleNode("EngineNO").InnerText;//发动机号
            string DealFaultBillName = mesDoc.SelectSingleNode("DealFaultBillName").InnerText;//排故单号
            string CustomerName = mesDoc.SelectSingleNode("CustomerName").InnerText;//客户名称
            string CustomerDealDate = mesDoc.SelectSingleNode("CustomerDealDate").InnerText;//客户确认时间
            string FaultBillContainerName = mesDoc.SelectSingleNode("FaultBillContainerName").InnerText;//排故任务流卡

            var updateSQL = @"update DealFaultBill set FaultBillContainerName='{0}',AuditDate=to_date('{1}','yyyy-MM-dd hh24:mi:ss'),
                                AuditEmployeeID=(select EmployeeID from Employee where FullName='{2}') where DealFaultBillName='{3}'";
            updateSQL = string.Format(updateSQL, FaultBillContainerName, CustomerDealDate, CustomerName, DealFaultBillName);
            if (OracleHelper.ExecuteSql(updateSQL) > 0)
            {
                return RespMsg("true", "接收数据成功", "S", "排故单处理结果审理接收成功");
            }
            else
            {
                return RespMsg("true", "接收数据成功", "E", "排故单处理结果审理接收失败");
            }
        }

        /// <summary>
        /// 故检提交单审理结果接口
        /// add by longb 2023-04-13 
        /// </summary>
        /// <param name="mesDoc"></param>
        /// <returns></returns>
        public string ZSGJCheckSubmitBillResult(XmlNode mesDoc) 
        {
            string ZSGJCheckSubmitBillNo = mesDoc.SelectSingleNode("ZSGJCheckSubmitBillNo").InnerText;//故检提交单号
            string AuditEmployeeFullName = mesDoc.SelectSingleNode("AuditEmployeeFullName").InnerText;//审核人
            string AuditDate = mesDoc.SelectSingleNode("AuditDate").InnerText;//审核时间
            string Conclusion = mesDoc.SelectSingleNode("Conclusion").InnerText;//顾客代表结论
            var updateSQL = @"update ZSGJCheckSubmitBill set Conclusion='{0}',AuditDate=to_date('{1}','yyyy-MM-dd hh24:mi:ss'),
                                AuditEmployeeID=(select EmployeeID from Employee where FullName='{2}') where ZSGJCheckSubmitBillNo='{3}'";
            updateSQL = string.Format(updateSQL, Conclusion, AuditDate, AuditEmployeeFullName, ZSGJCheckSubmitBillNo);
            if (OracleHelper.ExecuteSql(updateSQL) > 0)
            {
                return RespMsg("true", "接收数据成功", "S", "故检提交单审理结果接收成功");
            }
            else
            {
                return RespMsg("true", "接收数据成功", "E", "故检提交单审理结果接收失败");
            }
        }
        /// <summary>
        /// 周转/串件审理结果接口
        /// add by longb 2023-04-13 
        /// </summary>
        /// <param name="mesDoc"></param>
        /// <returns></returns>
        public string ExchangeBillResult(XmlNode mesDoc) 
        {
            string ExchangeName = mesDoc.SelectSingleNode("ExchangeName").InnerText;//周转/串件单号
            string GCJSB_EmployeeName = mesDoc.SelectSingleNode("GCJSB_EmployeeName").InnerText;//工程技术部人员
            string GCJSB_AuditDate = mesDoc.SelectSingleNode("GCJSB_AuditDate").InnerText;//工程技术部审批时间
            string JYJCSYB_EmployeeName = mesDoc.SelectSingleNode("JYJCSYB_EmployeeName").InnerText;//检验检测事业部人员
            string JYJCSYB_AuditDate = mesDoc.SelectSingleNode("JYJCSYB_AuditDate").InnerText;//检验检测事业部审批时间
            string SCZHB_EmployeeName = mesDoc.SelectSingleNode("SCZHB_EmployeeName").InnerText;//生产指挥部人员
            string SCZHB_AuditDate = mesDoc.SelectSingleNode("SCZHB_AuditDate").InnerText;//生产指挥部审批时间
            string CustomerName = mesDoc.SelectSingleNode("CustomerName").InnerText;//顾客代表
            string CustomerDealDate = mesDoc.SelectSingleNode("CustomerDealDate").InnerText;//顾客代表审核时间

            var updateSQL = @"update ExchangeBill set Conclusion='{0}',AuditDate=to_date('{1}','yyyy-MM-dd hh24:mi:ss'),
                                AuditEmployeeID=(select EmployeeID from Employee where FullName='{2}') where ExchangeName='{3}'";
            updateSQL = string.Format(updateSQL, GCJSB_EmployeeName, GCJSB_AuditDate, JYJCSYB_EmployeeName, ExchangeName);
            if (OracleHelper.ExecuteSql(updateSQL) > 0)
            {
                return RespMsg("true", "接收数据成功", "S", "周转/串件审理结果接收成功");
            }
            else
            {
                return RespMsg("true", "接收数据成功", "E", "周转/串件审理结果接收失败");
            }
        }

        #region longbin 质量接口
        #region 系统质量问题审理结果接口--
        //[WebMethod]
        public string qaProblemHearResultNotify(XmlNode mesDoc)
        {
            string dealName = mesDoc.SelectSingleNode("dealName").InnerText;//质量问题单号
            string orderNo = mesDoc.SelectSingleNode("orderNo").InnerText;//订单号
            string hearResult = mesDoc.SelectSingleNode("hearResult").InnerText;//审理结果
            string remark = mesDoc.SelectSingleNode("remark").InnerText;//审理备注
            //string remark = mesDoc.SelectSingleNode("remark").InnerText;//最终处理意见
            var para = new Dictionary<string, string>();
            para.Add("dealName", dealName);
            para.Add("orderNo", orderNo);
            para.Add("hearResult", hearResult);
            para.Add("remark", remark);
            if (qmsTOmes.updateQualityHistoryRecord(para))
            {
                return RespMsg("true", "接收数据成功", "S", "系统质量问题审理结果接收成功");
            }
            else
            {
                return RespMsg("true", "接收数据成功", "E", "系统质量问题审理结果接收失败");
            }
        }
        #endregion

        #region 首件鉴定目录接口--
        //[WebMethod]
        public string firstThingAuth(XmlNode mesDoc)
        {
            string firstThingAuthDirId = mesDoc.SelectSingleNode("firstThingAuthDirId").InnerText;//首件鉴定目录ID
            string componentsImgNo = mesDoc.SelectSingleNode("componentsImgNo").InnerText;//零组件图号
            string componentsName = mesDoc.SelectSingleNode("componentsName").InnerText;//零组件名称
            string keyImptFileLogo = mesDoc.SelectSingleNode("keyImptFileLogo").InnerText;//关重件标识
            string craftVersionNo = mesDoc.SelectSingleNode("craftVersionNo").InnerText;//工艺版本号
            string crdLevel = mesDoc.SelectSingleNode("crdLevel").InnerText;//级别
            string mainBuildUnit = mesDoc.SelectSingleNode("mainBuildUnit").InnerText;//主制单位
            string remark = mesDoc.SelectSingleNode("remark").InnerText;//备注
            var para = new Dictionary<string, string>();
            if (string.IsNullOrWhiteSpace(firstThingAuthDirId)) { return RespMsg("false", "接收数据失败", "2", "首件鉴定目录字段【firstThingAuthDirId】不能为空"); }
            if (string.IsNullOrWhiteSpace(componentsImgNo)) { return RespMsg("false", "接收数据失败", "2", "零组件图号字段【componentsImgNo】不能为空"); }
            if (string.IsNullOrWhiteSpace(componentsName)) { return RespMsg("false", "接收数据失败", "2", "零组件名称字段【componentsName】不能为空"); }
            if (string.IsNullOrWhiteSpace(keyImptFileLogo)) { return RespMsg("false", "接收数据失败", "2", "关重件标识字段【keyImptFileLogo】不能为空"); }
            if (string.IsNullOrWhiteSpace(craftVersionNo)) { return RespMsg("false", "接收数据失败", "2", "工艺版本号字段【craftVersionNo】不能为空"); }
            if (string.IsNullOrWhiteSpace(crdLevel)) { return RespMsg("false", "接收数据失败", "2", "级别字段【crdLevel】不能为空"); }
            if (string.IsNullOrWhiteSpace(mainBuildUnit)) { return RespMsg("false", "接收数据失败", "2", "主制单位字段【mainBuildUnit】不能为空"); }
            para.Add("firstThingAuthDirId", firstThingAuthDirId);
            para.Add("componentsNo", componentsImgNo);
            para.Add("componentsName", componentsName);
            para.Add("keyImptFileLogo", keyImptFileLogo);
            para.Add("VersionNo", craftVersionNo);
            para.Add("Level", crdLevel);
            para.Add("BuildUnit", mainBuildUnit);
            para.Add("remark", remark);
            para.Add("IdentifyType", "1");
            if (qmsTOmes.InsertFirstIdentifyProduct(para))
            {
                return RespMsg("true", "接收数据成功", "S", "首件鉴定目录接收成功");
            }
            else
            {
                return RespMsg("true", "接收数据成功", "E", "首件鉴定目录接收失败");
            }
        }
        #endregion

        #region 首件鉴定控制点解除接口
        //[WebMethod]
        public string firstThingAuthDirControlPointRelease(XmlNode mesDoc)
        {
            string firstThingAuthDirId = mesDoc.SelectSingleNode("firstThingAuthDirId").InnerText;//首件鉴定目录ID
            string componentsImgNo = mesDoc.SelectSingleNode("componentsImgNo").InnerText;//零组件图号
            string componentsName = mesDoc.SelectSingleNode("componentsName").InnerText;//零组件名称
            string craftVersionNo = mesDoc.SelectSingleNode("craftVersionNo").InnerText;//工艺版本号
            string authCompleteDate = mesDoc.SelectSingleNode("authCompleteDate").InnerText;//鉴定完成日期
            string remark = mesDoc.SelectSingleNode("remark").InnerText;//备注
            var para = new Dictionary<string, string>();
            if (string.IsNullOrWhiteSpace(firstThingAuthDirId)) { return RespMsg("false", "接收数据失败", "2", "首件鉴定目录字段【firstThingAuthDirId】不能为空"); }
            para.Add("FirstIdentifyProductID", firstThingAuthDirId);
            para.Add("IdentifyType", "1");
            if (qmsTOmes.UpdateFirstIdentifyProduct(para))
            {
                return RespMsg("true", "接收数据成功", "S", "首件鉴定控制点解除成功");
            }
            else
            {
                return RespMsg("true", "接收数据成功", "E", "首件鉴定控制点解除失败");
            }

        }
        #endregion

        #region 质量评审目录接口--
        //[WebMethod]
        public string pushQaProductReviewDir(XmlNode mesDoc)
        {
            string qaProductReviewDirId = mesDoc.SelectSingleNode("qaProductReviewDirId").InnerText;//产品质量评审目录ID
            string componentsNo = mesDoc.SelectSingleNode("componentsNo").InnerText;//零(组)件号
            string componentsName = mesDoc.SelectSingleNode("componentsName").InnerText;//零(组)件名称
            string qprdLevel = mesDoc.SelectSingleNode("qprdLevel").InnerText;//级别
            string constructUnit = mesDoc.SelectSingleNode("constructUnit").InnerText;//主制单位
            string remark = mesDoc.SelectSingleNode("remark").InnerText;//备注
            if (string.IsNullOrWhiteSpace(qaProductReviewDirId)) { return RespMsg("false", "接收数据失败", "2", "产品质量评审目录字段【qaProductReviewDirId】不能为空"); }
            if (string.IsNullOrWhiteSpace(componentsNo)) { return RespMsg("false", "接收数据失败", "2", "零(组)件号字段【componentsNo】不能为空"); }
            if (string.IsNullOrWhiteSpace(componentsName)) { return RespMsg("false", "接收数据失败", "2", "零(组)件名称字段【componentsName】不能为空"); }
            if (string.IsNullOrWhiteSpace(qprdLevel)) { return RespMsg("false", "接收数据失败", "2", "级别字段【qprdLevel】不能为空"); }
            if (string.IsNullOrWhiteSpace(constructUnit)) { return RespMsg("false", "接收数据失败", "2", "主制单位字段【constructUnit】不能为空"); }
            var para = new Dictionary<string, string>();
            para.Add("firstThingAuthDirId", qaProductReviewDirId);
            para.Add("componentsNo", componentsNo);
            para.Add("componentsName", componentsName);
            para.Add("keyImptFileLogo", "");
            para.Add("VersionNo", "");
            para.Add("Level", qprdLevel);
            para.Add("BuildUnit", constructUnit);
            para.Add("remark", remark);
            para.Add("IdentifyType", "2");
            if (qmsTOmes.InsertFirstIdentifyProduct(para))
            {
                return RespMsg("true", "接收数据成功", "S", "质量评审目录接收成功");
            }
            else
            {
                return RespMsg("true", "接收数据成功", "E", "质量评审目录接收失败");
            }
        }
        #endregion

        #region 产品质量评审控制点解除接口
        //[WebMethod]
        public string qaProductReviewDirControlPointRelease(XmlNode mesDoc)
        {
            string qaProductReviewDirId = mesDoc.SelectSingleNode("qaProductReviewDirId").InnerText;//产品质量评审目录ID
            string componentsNo = mesDoc.SelectSingleNode("componentsNo").InnerText;//零(组)件号
            string componentsName = mesDoc.SelectSingleNode("componentsName").InnerText;//零(组)件名称
            string reviewCompleteDate = mesDoc.SelectSingleNode("reviewCompleteDate").InnerText;//评审完成日期
            if (string.IsNullOrWhiteSpace(qaProductReviewDirId)) { return RespMsg("false", "接收数据失败", "2", "产品质量评审目录字段【qaProductReviewDirId】不能为空"); }
            var para = new Dictionary<string, string>();
            para.Add("FirstIdentifyProductID", qaProductReviewDirId);
            para.Add("IdentifyType", "2");
            if (qmsTOmes.UpdateFirstIdentifyProduct(para))
            {
                return RespMsg("true", "接收数据成功", "S", "产品质量评审控制点解除成功");
            }
            else
            {
                return RespMsg("true", "接收数据成功", "E", "产品质量评审控制点解除失败");
            }
        }
        #endregion

        #region 工艺评审控制点接口
        //[WebMethod]
        public string pushCraftReviewDir(XmlNode mesDoc)
        {
            string craftReviewDirId = mesDoc.SelectSingleNode("craftReviewDirId").InnerText;//工艺评审目录ID ---开卡使用
            string reviewFileNo = mesDoc.SelectSingleNode("reviewFileNo").InnerText;//评审文件号(零件号)
            string fileName = mesDoc.SelectSingleNode("fileName").InnerText;//文件名称(零件名称)
            string keyImptFileLogo = mesDoc.SelectSingleNode("keyImptFileLogo").InnerText;//关重件标识
            string crdLevel = mesDoc.SelectSingleNode("crdLevel").InnerText;//级别
            string constructUnit = mesDoc.SelectSingleNode("constructUnit").InnerText;//主制单位
            string remark = mesDoc.SelectSingleNode("remark").InnerText;//备注
            if (string.IsNullOrWhiteSpace(craftReviewDirId)) { return RespMsg("false", "接收数据失败", "2", "工艺评审目录字段【craftReviewDirId】不能为空"); }
            if (string.IsNullOrWhiteSpace(reviewFileNo)) { return RespMsg("false", "接收数据失败", "2", "评审文件号(零件号)字段【reviewFileNo】不能为空"); }
            if (string.IsNullOrWhiteSpace(fileName)) { return RespMsg("false", "接收数据失败", "2", "文件名称(零件名称)字段【fileName】不能为空"); }
            if (string.IsNullOrWhiteSpace(keyImptFileLogo)) { return RespMsg("false", "接收数据失败", "2", "关重件标识字段【keyImptFileLogo】不能为空"); }
            if (string.IsNullOrWhiteSpace(crdLevel)) { return RespMsg("false", "接收数据失败", "2", "级别字段【crdLevel】不能为空"); }
            if (string.IsNullOrWhiteSpace(constructUnit)) { return RespMsg("false", "接收数据失败", "2", "主制单位字段【constructUnit】不能为空"); }

            var para = new Dictionary<string, string>();
            para.Add("firstThingAuthDirId", craftReviewDirId);
            para.Add("componentsNo", reviewFileNo);
            para.Add("componentsName", fileName);
            para.Add("keyImptFileLogo", keyImptFileLogo);
            para.Add("VersionNo", "");
            para.Add("Level", crdLevel);
            para.Add("BuildUnit", constructUnit);
            para.Add("remark", remark);
            para.Add("IdentifyType", "3");
            if (qmsTOmes.InsertFirstIdentifyProduct(para))
            {
                return RespMsg("true", "接收数据成功", "S", "工艺评审控制点接收成功");
            }
            else
            {
                return RespMsg("true", "接收数据成功", "E", "工艺评审控制点接收失败");
            }
        }
        #endregion

        #region 工艺评审控制点解除接口
        //[WebMethod]
        public string craftReviewDirControlPointRelease(XmlNode mesDoc)
        {
            string craftReviewDirId = mesDoc.SelectSingleNode("craftReviewDirId").InnerText;//工艺评审目录ID
            string reviewFileNo = mesDoc.SelectSingleNode("reviewFileNo").InnerText;//零(组)件号
            string fileName = mesDoc.SelectSingleNode("fileName").InnerText;//零(组)件名称
            string reviewCompleteDate = mesDoc.SelectSingleNode("reviewCompleteDate").InnerText;//评审完成日期
            if (string.IsNullOrWhiteSpace(craftReviewDirId)) { return RespMsg("false", "接收数据失败", "2", "工艺评审目录字段【constructUnit】不能为空"); }
            var para = new Dictionary<string, string>();
            para.Add("FirstIdentifyProductID", craftReviewDirId);
            para.Add("IdentifyType", "3");
            if (qmsTOmes.UpdateFirstIdentifyProduct(para))
            {
                return RespMsg("true", "接收数据成功", "1", "工艺评审控制点解除成功");
            }
            else
            {
                return RespMsg("true", "接收数据成功", "2", "工艺评审控制点解除失败");
            }
        }
        #endregion

        private string RespMsg(string isSuccess, string message, string success, string dmessage)
        {
            return string.Format("<?xml version=\"1.0\" encoding=\"UTF-8\"?><RespMsg><header><sysName>APP_MES</sysName><isSuccess>{0}</isSuccess><message>{1}</message></header><document><![CDATA[<TETTYP><RTYPE>{2}</RTYPE><RTMSG>{3}</RTMSG></TETTYP>]]></document></RespMsg>", isSuccess, message, success, dmessage);
        }
        #endregion
    }
}
